#include "Point.h"

void Point::set(int x1, int y1)
{	
	m_x = x1;
	m_y = y1;
}

void Point::input()
{
	int x1, y1;
	cout << "Please enter the X coordinate: ";
	cin >> x1;
	cout << "Please enter the Y coordinate: ";
	cin >> y1;

	set (x1, y1);
}

bool Point::draw(char ch='*') const
{
	if (isValidPrintPoint(m_x , m_y))
	{
		gotoxy( m_x, m_y);
		cout << ch << endl;
		return true;
	}
	return false;
}

void Point::clear() const
{
	if (m_x < 0 && m_x > MAX_SCREEN_X && m_y < 0 && m_y > MAX_SCREEN_Y)
	{
		gotoxy( m_x, m_y);
		cout << ' ' << endl;
	}
}

int Point::isPointInBorders(Point &DR,Point &UL) const
{
	// if the point is inside the two points - return 1
	// else return 0
	int x = this->getx();
	int y = this->gety();
	if ((y <= DR.gety() && x <= DR.getx()) &&
		(y >= UL.gety() && x >= UL.getx()))
		return 1;
	else
		return 0;
}

void Point::printPoint (const Point p, MyScreen * scr, char frameCh) 
	{
		int x = p.getx(), y = p.gety();
		if (isValidPrintPoint (x , y))
		{
			if (scr != NULL)
			{
				scr->set(x , y ,frameCh);
			}
			else
			{
				gotoxy(x , y);
				cout << frameCh;
			}
		}
	}

bool Point::checkIfPointOnScr (const Point & p , const MyScreen & scr)
{
	int x = p.getx(), y = p.gety();
	if (scr.getChar(x,y) == '*')
		return true;
	else if (!isValidPrintPoint (x , y))
		return true;
	else 
		return false;

}